package com.ngds.library.downloadcenter;

import android.content.Context;
import android.database.Cursor;

/**
 * AppDownloadHelper
 * Description:下载中心接口，包含开放的下载相关功能
 * Author:walker lx
 * Date :14-5-14
 */
public interface AppDownloadHelper {
	/**
	 * 广播通知，删除一项
	 */
	public final static String ACTION_DOWNLOAD_DELETE =
			Downloads.Impl.AUTHORITIES + ".intent.action.DOWNLOAD_DELETE";

	/**
	 * Broadcast intent action sent by the download manager when a download
	 * completes.
	 */
	public final static String ACTION_DOWNLOAD_COMPLETE =
			Downloads.Impl.AUTHORITIES + ".intent.action.DOWNLOAD_COMPLETE";

	/**
	 * Broadcast intent action sent by the download manager when the user clicks
	 * on a running download, either from a system notification or from the
	 * downloads UI.
	 */
	public final static String ACTION_NOTIFICATION_CLICKED =
			Downloads.Impl.AUTHORITIES + ".intent.action.DOWNLOAD_NOTIFICATION_CLICKED";

	/**
	 * Intent action to launch an activity to display all downloads.
	 */
	public final static String ACTION_VIEW_DOWNLOADS =
			Downloads.Impl.AUTHORITIES + ".intent.action.VIEW_DOWNLOADS";


	/**
	 * Intent extra included with {@link #ACTION_VIEW_DOWNLOADS} to start
	 * DownloadApp in sort-by-size mode.
	 */
	public final static String INTENT_EXTRAS_SORT_BY_SIZE =
			"android.app.DownloadManager.extra_sortBySize";

	/**
	 * Intent extra included with {@link #ACTION_DOWNLOAD_COMPLETE} intents,
	 * indicating the ID (as a long) of the download that just completed.
	 */
	public static final String EXTRA_DOWNLOAD_ID = "extra_download_id";
	
	/**文件ID */
	public final static String EXTRA_FILE_ID = "extra_file_id";
	/** 文件名称 */
	public static final String EXTRA_FILE_NAME ="extra_file_name";
	
	/** 被删除的文件类型 */
	public final static String EXTRA_FILE_TYPE = "extra_file_type";
	
	/**
	 * Intent extra included with {@link #ACTION_DOWNLOAD_COMPLETE} intents,
	 * indicating the URI (as a string) of the download that just completed.
	 */
	public static final String EXTRA_DOWNLOAD_URI = "extra_download_uri";

	/**
	 * When clicks on multiple notifications are received, the following
	 * provides an array of download ids corresponding to the download
	 * notification that was clicked. It can be retrieved by the receiver of
	 * this Intent using
	 * {@link android.content.Intent#getLongArrayExtra(String)}.
	 */
	public static final String EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS = "extra_click_download_ids";

	/**
	 * create downloader
	 *
	 * @param context
	 * @param effectiveUrl
	 * @param fileDir
	 * @param fileName
	 * @return downloaderId（下载对象id）
	 * @throws com.ngds.library.downloadcenter.DownloadStopedException
	 */
	public long createAndStartDownload(Context context, String effectiveUrl, String fileDir,
			String fileName)
					throws DownloadStopedException;

	/**
	 * create downloader with notification
	 *
	 * @param context
	 * @param effectiveUrl
	 * @param fileDir
	 * @param fileName
	 * @return
	 * @throws com.ngds.library.downloadcenter.DownloadStopedException
	 */
	public long createAndStartDownloadWithNotification(Context context, String effectiveUrl,
			String fileDir, String fileName) throws DownloadStopedException;

	/**
	 * resume download
	 *
	 * @param ids the IDs of the downloads to be resumed
	 * @return the number of downloads actually resumed, -1 if exception or method not exist
	 */
	public int resumeDownload(long... ids);

	/**
	 * pause download
	 *
	 * @param ids the IDs of the downloads to be paused
	 * @return the number of downloads actually paused, -1 if exception or method not exist
	 */
	public int pauseDownload(long... ids);

	/**
	 * delete download
	 *
	 * @param ids the IDs of the downloads to be delete
	 */
	public void deleteDownload(long... ids);

	/**
	 * get cursor filter with downloadStatus
	 *
	 * @param isDownloadFinished
	 * @return downloaded or not downloaded info's cursor
	 */
	public Cursor queryDownloaderByStatus(boolean isDownloadFinished);

	/**
	 * @return downloaderId in current position
	 */
	public long getDownloaderId(Cursor cursor) throws IllegalArgumentException;

	/**
	 * get downloaded byte, total byte and download status
	 *
	 * @param downloadId
	 * @return a int array with three elements
	 */
	public DownloadBytesAndStatusWrapper getBytesAndStatus(long downloadId);

	/**
	 * get downloaded byte, total byte and download status by url index
	 *
	 * @param url
	 * @return null if not exit.
	 */
	public DownloadBytesAndStatusWrapper getBytesAndStatus(String url);

	/**
	 * judge whether is download successed by download
	 *
	 * @param downloadStatus
	 * @return
	 */
	public boolean isDownloadedSuc(int downloadStatus);

	public boolean isDownloadedSuc(String url);

	public String getFileName(long downloadId);

	public String getDownloadUrl(long downloadId);

	public String getErrorMsg(long downloadId);

	/**
	 * quit AppDownloadHelper
	 */
	public void exit();

	/**
	 * start AppDownloadHelper ,begin unfinished download tasks
	 */
	public void start();

	void changeDownloadNetSetting(Context context, boolean isWifyOnly);

	/**
	 * get current user download setting,only be userd for AppDownloadManager auto manager download's settings,
	 * now,it's deprecate to use,recommend developer to manager download by hand.
	 *
	 * @param context
	 * @return
	 */
	public int getCurrentUserDownloadSettings(Context context);

	/**
	 * set download setting environment,only be userd for AppDownloadManager auto manager download's settings,
	 * now,it's deprecate to use,recommend developer to manager download by hand.
	 *
	 * @param context
	 * @param settting DownloadNetEnvironmentSettings
	 */
	public void setDownloadSettings(Context context, int settting);

	/**
	 * set extra info that you want to store or describe your downloader
	 *
	 * @param description
	 * @param url         which downloader to set.
	 */
	public void setDescription(Context context, String description, String url);

	/**
	 * get extra info from target url
	 *
	 * @param url
	 * @return
	 */
	public String getDescription(Context context, String url);
}
